package com.order.controller;

import com.order.service.User;
import com.order.vo.OrderInfo;
import com.order.vo.PriceVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

//    @GetMapping("/{eid}")
//    public PriceVO get(@PathVariable Long eid, @AuthenticationPrincipal(expression = "#this.id") Long id){
//        log.info("user is {}",id);
////        PriceVO forObject = restTemplate.getForObject("http://localhost:8080/price/" + id, PriceVO.class);
//        return new PriceVO();
//    }
//
//    @PostMapping("/create")
//    public PriceVO create(@RequestBody PriceVO priceVO,@AuthenticationPrincipal String username){
//        log.info("user is {}",username);
//        return new PriceVO();
//    }

    @GetMapping("/{eid}")
    public OrderInfo get(@PathVariable Long eid, @RequestHeader String username){
        log.info("username is {}",username);
        log.info("id is {}",eid);
//        PriceVO forObject = restTemplate.getForObject("http://localhost:8080/price/" + id, PriceVO.class);
        OrderInfo info=new OrderInfo();
        info.setId(eid);
        info.setProductId(Integer.parseInt(String.valueOf(eid))*5);
        info.setUsername(username);
        return info;
    }

    @PostMapping("/create")
    public PriceVO create(@RequestBody PriceVO priceVO,@RequestHeader String username){
        log.info("user is {}",username);
        return new PriceVO();
    }
}
